package com.example.exam2;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, View.OnFocusChangeListener {
    RadioButton pswBtn;
    RadioButton codeBtn;
    TextView pswTv;
    EditText pswEt;
    EditText phoneEt;
    Button forgetBtn;
    LinearLayout secondLayout;
    LinearLayout firstLayout;
    CheckBox remCb;
    RadioGroup radioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pswBtn = findViewById(R.id.btn_psw);
        codeBtn = findViewById(R.id.btn_code);
        pswTv = findViewById(R.id.tv_psw);
        pswEt = findViewById(R.id.et_psw);
        phoneEt = findViewById(R.id.et_phone);
        forgetBtn = findViewById(R.id.btn_psw_forget);
        secondLayout = findViewById(R.id.ll_second);
        firstLayout = findViewById(R.id.ll_first);
        remCb = findViewById(R.id.cb_rem);
        radioGroup = findViewById(R.id.radio_group);
        radioGroup.setOnCheckedChangeListener(this);
        phoneEt.setOnFocusChangeListener(this);
        pswEt.setOnFocusChangeListener(this);
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.btn_code:
                pswTv.setText("    验证码：");
                pswEt.setHint("请输入验证码");
                forgetBtn.setText("获取验证码");
                remCb.setVisibility(View.INVISIBLE);
                break;
            default:
                pswTv.setText("登录密码：");
                pswEt.setHint("请输入密码");
                forgetBtn.setText("忘记密码");
                remCb.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        switch (v.getId()) {
            case R.id.et_phone:
                firstLayout.setBackgroundResource(R.drawable.shape_edit_focus);
                secondLayout.setBackgroundResource(R.drawable.shape_edit_normal);
                break;
            case R.id.et_psw:
                secondLayout.setBackgroundResource(R.drawable.shape_edit_focus);
                firstLayout.setBackgroundResource(R.drawable.shape_edit_normal);
                break;
            default:
                secondLayout.setBackgroundResource(R.drawable.shape_edit_normal);
                firstLayout.setBackgroundResource(R.drawable.shape_edit_normal);
                break;
        }
    }
}